using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEditor;
using UnityEngine.Serialization;
using Sirenix.Utilities;
using System;
#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using Pangoo.Common;


namespace MetaTable
{
    public class MetaTableNewConfig
    {
        [HideInInspector]
        public OdinEditorWindow Window;

        [HideInInspector]
        public MetaTableMainConfig MainConfig;

        [LabelText("命名空间")]
        public string Namespace;

        [LabelText("中文名")]
        public string Name;

        [FolderPath]
        [LabelText("包路径")]
        public string PackageDir;

        [Button]
        public void Create()
        {
            if (Namespace.IsNullOrWhiteSpace())
            {
                Debug.LogError("命名空间不能为空");
                return;
            }

            if (PackageDir.IsNullOrWhiteSpace())
            {
                Debug.LogError("包目录不能为空");
                return;
            }

            var config = ScriptableObject.CreateInstance<MetaTableConfig>();
            config.Namespace = Namespace;
            config.PackageDir = PackageDir;
            config.Name = Name;
            if (!File.Exists(config.ConfigFilePath))
            {
                DirectoryUtility.ExistsOrCreate(config.StreamResConfigDir);
                AssetDatabase.SaveAssets();
                AssetDatabase.CreateAsset(config, config.ConfigFilePath);
                AssetDatabase.SaveAssets();
            }
            else
            {
                config = AssetDatabase.LoadAssetAtPath<MetaTableConfig>(config.ConfigFilePath);
                config.Name = Name;
                config.Namespace = Namespace;
            }

            MainConfig?.UpdateAllConfigs();
            Window?.Close();



        }

    }
}
#endif